<%@ page contentType="text/html; charset=utf-8" language="java"  errorPage="" %>
<%@ page import="java.sql.*,java.util.*,java.io.*,javax.servlet.*,oracle.jdbc.driver.OracleDriver"%>
<%@ page import="com.ucap.system.db.*"%>
<%@ page import="com.ucap.util.userdao.*"%>
<%@ page import="com.ucap.wcm.*,com.ucap.rpc.RpcUtils"%>
<%@ page import="com.ucap.base.exception.wcm.WebContentManagementException"%>
<%@ page import="com.ucap.wcm.model.*"%>
<%@ page import="com.ucap.base.model.wcm.Website"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>应用组件</title>

<style type="text/css">
<!--
body{
	font-size: 12px;
	line-height: 25px;
	font-weight: normal;
	color: #535353;
	text-decoration: none;
	padding: 0px;
	margin-top: 20px;
	margin-right: 0px;
	margin-bottom: 20px;
	margin-left: 0px;
	text-align: left;
}
ul{
	width: 600px;
	padding: 0px;
	margin-top: 0px;
	margin-right: auto;
	margin-bottom: 0px;
	margin-left: auto;
}
li{
	background-image: url(1.jpg);
	background-repeat: no-repeat;
	padding-left: 25px;
	width: 275px;
	height: 30px;
	margin: 0px;
	float: left;
	list-style-type: none;
	overflow: hidden; 
}
.div1{
	height:400px;
	overflow-y:auto;
	scrollbar-face-color: #efefef;
	scrollbar-shadow-color: #f8f8f8;
	scrollbar-highlight-color: #f8f8f8;
	scrollbar-3dlight-color: #f8f8f8;
	scrollbar-darkshadow-color: #f8f8f8;
	scrollbar-track-color: #f8f8f8;
	scrollbar-arrow-color: #666666;
	width: 640px;
	margin-right: auto;
	margin-left: auto;
	}
-->
</style>
</head>
<%!
	public class UserWebsite1 {
	public UserWebsite1()
	{
		
	}
	public Website getWebsite(String sitecode,String url)
	{
		Website website = null;
		WebsiteService ws1 = RpcUtils.findService(url, WebsiteService.class);
		if (!sitecode.equals("")&&sitecode!=null)
		{
			try {
				website = ws1.getWebsiteByCode(sitecode);
			} catch (WebContentManagementException e) {
				e.printStackTrace();
			}
		}
		return website;
	}
	public List<String []> getUserWebsite(String userid, String state, String url) {
		//List<Website> website = new ArrayList<Website>();
		List<String []> website = new ArrayList<String []>();
		String sqlcms = "";
		DataBase db = null;
		//WebsiteService ws1 = RpcUtils.findService(url, WebsiteService.class);
		
			if (userid.equals("99999999999999991")) {

				try {
					db = DataBaseFactory.getDataBase();
					String where = "";
					if (!state.equals("0"))
						where = " and t.status='"+state+"'";
					sqlcms = "select t.code_name,t.name from cms_website t  where t.website_id not in (select t.website_id from cms_website t where t.parent_website_id in (select t.website_id from cms_website t where t.parent_website_id in ('81d5c7420dd24675bcf92083e0939060','699f22bda2524064a31e54db7e777d5f','f4e59f980d0842b1aff000e59ccbc68c')))" +where;
					System.out.println(sqlcms);
					PreStatement pre = db.setStatement(sqlcms);
					RecordSet rec = db.executeQuery();
					while (rec.next()) {
						String site[] = new String [2];
						site[0] = rec.getString("name");
						site[1] = rec.getString("code_name");
						website.add(site);
					}
					rec.close();
					pre.close();
				} catch (Exception e) {
					e.printStackTrace();
				} finally {
					if (db != null) {
						db.close();
					}
				}
			} else {
				try {
					db = DataBaseFactory.getDataBase();
					int cjgly =0;
					sqlcms = "select * from cms_user_role t where t.user_id='"+ userid + "' and t.role_id='ADMINISTRATOR_ROLE'";
					System.out.println(sqlcms);
					PreStatement pre = db.setStatement(sqlcms);
					RecordSet rec = db.executeQuery();
					if (rec.next()) {
						cjgly = 1;
					}
					rec.close();
					pre.close();
					
					String where = "";
					if (!state.equals("0"))
						where = " and t1.status='"+state+"'";
					if (cjgly==0)
					{
					sqlcms = "select t1.name,t1.code_name from CMS_WEBSITE_PRIVS t  left join CMS_WEBSITE t1 on t.res_id=t1.website_id  where grantee_id='"+ userid + "' and view_website='1'" +where;
					}
					else if (cjgly==1)
					{
						sqlcms = "select t1.name,t1.code_name from cms_website t1 where 1=1 "+where;
					}
					System.out.println(sqlcms);
					pre = db.setStatement(sqlcms);
					rec = db.executeQuery();
					while (rec.next()) {
						String site[] = new String [2];
						site[0] = rec.getString("name");
						site[1] = rec.getString("code_name");
						website.add(site);
					}
					rec.close();
					pre.close();
				} catch (Exception e) {
					e.printStackTrace();
				} finally {
					if (db != null) {
						db.close();
					}
				}
			}
		
		return website;
	}
}


%>

<script type="text/javascript">
var api = frameElement.api, W = api.opener;
function a(site,code)
{
	var text = document.getElementById('text').value;
	// W.document.getElementById('website').value=site;
	 if (text!="")
	 	W.document.getElementById(text).value=code;
	 api.close();
}
</script>



<body>
<div class="div1" >
<ul>
	<%
	String userid = request.getParameter("userid")==null?"4510837f06d84acb8c373dba782b52bc":request.getParameter("userid");
	String state = request.getParameter("state")==null?"3":request.getParameter("state");
	String text = request.getParameter("text")==null?"":request.getParameter("text");//获取父窗体站点编码输入框name
	out.print("<input name='text' type='hidden' id='text' value='"+text+"' />");
	final String URL2 = "http://htgl.cnsn.gov.cn/website-webapp/services/WebsiteService";
	UserWebsite1 cd = new UserWebsite1();
	//List<Website> wl = cd.getUserWebsite(userid, state,URL2);
	List<String []> wl = cd.getUserWebsite(userid, state,URL2);
	
	if (wl!=null)
	{
		for (int i =0;i<wl.size();i++)
		{
			String []site = wl.get(i);
			out.println("<li title='"+site[0]+"("+site[1]+")'><span onclick='a(\""+site[0]+"\",\""+site[1]+"\")' style='cursor:pointer;' >"+site[0]+"("+site[1]+")</span></li>");
		}
	}
	%>
</ul>
</div>
</body>
</html>
